package com.example.kotlin01

import kotlinx.coroutines.*

class MyActivity:CoroutineScope by CoroutineScope(Dispatchers.Default) {

    fun onDestory(){
        cancel()
    }
    fun doSomthing(){
        repeat(10){ i->
            launch {
                delay((i + 1) * 200L) // var
                println("这是第${i}次执行...")
            }
        }

    }


}

suspend fun main() {
    val myActivity = MyActivity()
    myActivity.doSomthing()
    delay(500)
    myActivity.onDestory()
    delay(2000)
}